﻿
@{Layout = "~/Views/Shared/_Layout.cshtml";}
@{
    ViewBag.Title = "Add";
}

<h1>Add</h1>
<p class="Subtitle">Here you can add a room</p>
<p style="color:Red">@ViewData["message"]</p>
<form method="post">
    <table class="Form" id="expandable">
        <tr><th>Room ID</th></tr>
        <tr><td><input = type="text" name="inRoomID" value="@ViewData["roomID"]" /><i>(Ex: 21E404)</i></td></tr>
        <tr></tr>
        <tr><th>Name</th></tr>
        <tr><td><input = type="text" name="inRoomName" value="@ViewData["roomName"]" /><i>(Ex: Aula Magma)</i></td></tr>
        <tr></tr>
        <tr><th>Capacity</th></tr>
        <tr><td><input = type="text" name="inRoomCapacity" size="1" value="@ViewData["roomCapacity"]" /><i>(Ex: 50)</i></td></tr>
        <tr></tr>
        <tr><th>Description</th></tr>
        <tr><td><textarea name="inRoomDescription" rows="4" cols="20">@ViewData["roomDescription"] </textarea><i>(Max 50 characters)</i></td></tr>
        <tr></tr>
        <tr><th>Properties:</th></tr>
        <tr><th>Name</th><th>Value<i>(0 = unknown)</i></th></tr>
        <tr></tr>
    </table>
    <table style="margin:8px 0px"; border="0" width="10">
    <tr><td><input class="Button" type="button" id="expand" value="Add Property" onclick="addField()" /></td> <td><input class="Button" type="submit" value="Add" /></td></tr>
    </table>
</form>

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        @{ if(ViewData["message"] != "" && ViewData["message"] != null)
           {
                string[] arr1 = ViewData["props"] as string[];
                string[] arr2 = ViewData["propVals"] as string[];
                int count = arr1.Length;
                int i;
                for (i=0; i < count; i++)
                {
                    <text>addFilledField('@arr1[i]', '@arr2[i]');</text>
                }
           }
           else{
               <text>addField();</text>
               }
          }  
    });

    var numid = 0;
    var fieldDataString = "@ViewData["fieldData"]";
    var fieldData = fieldDataString.split(",");
    function addField() {
        $('#expandable').append("<tr><td><input type='text' name='inField' id='inField"+ numid +"' /></td><td><input type='text' size='1' name='inFieldVals' /></td></tr>");
        $("#inField" + numid).autocomplete({ source: fieldData, delay: 400, max: 10 });
        numid++;
    }
    function addFilledField(value1, value2){
        $('#expandable').append("<tr><td><input type='text' name='inField' id='inField"+ numid +"' value='" + value1 + "' /></td><td><input type='text' size='1' name='inFieldVals' value='" + value2 + "' /></td></tr>");
        $("#inField" + numid).autocomplete({ source: fieldData, delay: 400, max: 10 });
        numid++;
    }


</script>